package com.feng.test.svg;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.jfree.graphics2d.svg.SVGGraphics2D;

/**
 * @author HuangSuip
 */
public class GraphicsAffineTransform {

    public static void main(String[] args) {
        SVGGraphics2D graphics2D = new SVGGraphics2D(1000, 1000);
        graphics2D.setStroke(new BasicStroke(5));
        int x1 = 0;
        int x2 = 0;
        int x3 = 50;

        int y1 = 0;
        int y2 = 50;
        int y3 = 0;

        int[] dotX = {x1, x2, x3};
        int[] dotY = {y1, y2, y3};
        Polygon polygon = new Polygon(dotX, dotY, 3);
        graphics2D.draw(polygon);
        graphics2D.fillOval(300, 300, 5, 5);
        graphics2D.fillOval(100, 100, 5, 5);
        AffineTransform at = new AffineTransform();
        at.translate(100, 100);
        graphics2D.setTransform(at);
        //graphics2D.draw(polygon);

        for (int i = 0; i < 180; i = i + 10) {
            at = new AffineTransform();
            Color color = new Color(i, 0, 0);
            graphics2D.setColor(color);
            if (i == 20) {
                at.rotate(Math.toRadians(90), 300, 300);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.translate(100, 0);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.rotate(Math.toRadians(90), 100, 100);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);


                dotX = new int[]{600, 600 - 50, 600};
                dotY = new int[]{300, 300, 300 - 50};
                Polygon polygon2 = new Polygon(dotX, dotY, 3);
                graphics2D.setColor(Color.blue);
                graphics2D.setTransform(null);
                graphics2D.draw(polygon2);
                System.out.println(graphics2D.getTransform());
                 at = new AffineTransform();

                at.rotate(Math.toRadians(90+60) , 300, 300);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);
                graphics2D.rotate(10);
/*                at.translate(100, 100);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.rotate(Math.toRadians(90));
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.translate(-300, -300);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);*/



            } else if (i == 200) {
                at.rotate(Math.toRadians(90), 100, 100);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.translate(50, 50);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);

                at.rotate(Math.toRadians(90), 300, 300);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);
            } else {
/*                at.rotate(Math.toRadians(i + 90), 300, 300);
                graphics2D.setTransform(at);
                graphics2D.draw(polygon);*/
            }
        }

        File file = new File("E:\\ppt\\slide\\test.svg");
        try {
            OutputStream os = new FileOutputStream(file);
            os.write(graphics2D.getSVGElement().getBytes());
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("finish");
    }
}
